package com.Helper;
import com.database.*;

import java.sql.*;
import java.util.ArrayList;

public class TestDriver 
{
	private static Connection connection = null;
	
	public static void Setup(Connection con) throws SQLException
	{
		connection = con;
		System.out.println("connection established.");
	}
	
	public static void InsertTest() throws SQLException
	{
		InsertCustomer();
		InsertAdmin();
		InsertFlightList();
		InsertSeatList("AC8080");
		InsertSeatList("AC8081");
		InsertSeatList("AC8082");
		InsertSeatList("CA991");
	}
	
	public static void InsertCustomer() throws SQLException
	{
		CustomerDB db = new CustomerDB ("ehan", "pass", "edward", "han", "ehan@mail.com", 123, 1000);
		db.Setup(connection);
		db.Insert();
	}
	
	public static void InsertAdmin() throws SQLException
	{
		AdministratorDB db = new AdministratorDB(1, "pass", "edward", "han", "ehan@mail.com", 123);
		db.Setup(connection);
		db.Insert();
	}
		
	public static void InsertFlightList() throws SQLException
	{
		FlightDB db = new FlightDB("AC8080", "Air Canada", "Vancouver", "2012-11-28 10:00:00", 
				   "Edmonton", "2012-11-28 12:00:00", AirplaneStatus.onTime, 100f,
				   122, "1A", 200f
				  );
		
		FlightDB db1 = new FlightDB("AC8081", "Air Canada", "Edmonton", "2012-11-28 9:00:00", 
				   "Toronto", "2012-11-28 17:00:00", AirplaneStatus.onTime, 200f,
				   122, "2A", 200f
				  );
		
		FlightDB db2 = new FlightDB("AC8082", "Air Canada", "Toronto", "2012-11-28 7:00:00", 
				   "Vancouver", "2012-11-28 12:00:00", AirplaneStatus.onTime, 300f,
				   122, "3A", 200f
				  );

		FlightDB db3 = new FlightDB("CA991", "Air China", "Vancouver", "2012-11-28 8:00:00", 
				   "Beijing", "2012-11-28 21:00:00", AirplaneStatus.onTime, 400f,
				   122, "1A", 200f
				  );
				
		
		db.Setup(connection);
		db1.Setup(connection);
		db2.Setup(connection);
		db3.Setup(connection);
		
		db.Insert();
		db1.Insert();
		db2.Insert();
		db3.Insert();
	}
	
	public static void InsertSeat() throws SQLException
	{
		SeatInfo info = new SeatInfo();
		info.seatID = "A01";
		info.flightID = "AC8080";
		info.status = "empty";
		
		SeatDB db = new SeatDB(info);
		db.Setup(connection);
		db.Insert();
	}
	
	public static void InsertSeatList(String flightID) throws SQLException
	{
		String s0 = "ABEF";
		String s1 = "ABCDEF";
		
		for (int i = 0; i < s0.length(); i++)
		{
			for (int j = 10; j <= 11; j++)
			{
				SeatInfo info = new SeatInfo();
				String c = s0.charAt(i) + "";
				info.seatID = c + j;
				info.flightID = flightID;
				info.status = "empty";
				SeatDB db = new SeatDB(info);
				db.Setup(connection);
				db.Insert();
			}
		}
		
		for (int i = 0; i < s1.length(); i++)
		{
			for (int j = 12; j <= 30; j++)
			{
				SeatInfo info = new SeatInfo();
				String c = s1.charAt(i) + "";
				info.seatID = c + j;
				
				info.flightID = flightID;
				info.status = "empty";
				SeatDB db = new SeatDB(info);
				db.Setup(connection);
				db.Insert();

			}
		}		
	}
		
	public static void InsertReservation() throws SQLException
	{	
		ReservationDB db = new ReservationDB("edward", "han", 150f, 0, "chicken", "A01", "ehan", "AC8080");
		db.Setup(connection);
		db.Insert();	
	}
	
	public static void DeleteAllReservations() throws SQLException
	{
		ReservationDB db = new ReservationDB();
		db.Setup(connection);
		db.DeleteAll();
	}

	public static void DeleteAllFlights() throws SQLException 
	{
		FlightDB db = new FlightDB();
		db.Setup(connection);
		db.DeleteAll();
	}
	
	public static void PrintDestList() throws SQLException
	{
		FlightHelper.Setup(connection);
		
		ArrayList<DestInfo> list = FlightHelper.GetDestStats();
		
		for (int i = 0; i < list.size(); i++)
		{
			System.out.println(list.get(i).arrivalLocation + " " + list.get(i).count);
		}
	}
	

	
}
